package com.lizhenhua.timeoutcancel.service;

import com.github.wxpay.sdk.WXPay;
import com.lizhenhua.fmmall.entity.Orders;
import com.lizhenhua.timeoutcancel.feignClient.OrderCloseFeignClient;
import com.lizhenhua.timeoutcancel.feignClient.OrderTimeoutQueryClient;
import com.lizhenhua.timeoutcancel.feignClient.UpdateOrderStatusFeignClient;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@RabbitListener(queues = "q2")
public class ReceiveMessageFromMq {
    @Autowired
    private OrderTimeoutQueryClient orderTimeoutQueryClient;

    @Autowired
    private UpdateOrderStatusFeignClient updateOrderStatusFeignClient;
    WXPay wxPay = new WXPay(new MyPayConfig());


    @Autowired
    private OrderCloseFeignClient orderCloseFeignClient;

    @RabbitHandler
    public void checkAmdCloseOrder(String orderId, Channel channel, Message message) throws IOException {

        try {
            /**
             *    根据订单编号 查询当前 订单信息
             *    如果订单 状态为未支付  则拿着订单编号 向微信平台确认
             *    支付则 修改订单状态
             *    未支付则关闭订单
             *
             */

            System.out.println("订单延时取消成功----------------！");
            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);  // false 表示为是否是批量
        } catch (Exception e) {

            System.out.println("定时关闭订单出现异常");

            channel.basicNack(message.getMessageProperties().getDeliveryTag(), true, false);
        }

    }

}
